<?php
defined('IN_PHPCMS') or exit('No permission resources.');
class upfiles{
    public $upfile = "uploadfile/system/banner/"; //上传目录
  
    public $maxsize= 1024000;
    //上传方法开始
    function upfile($filename){
        $newname = date("Ymdhs").mt_rand(0,9).mt_rand(0,9).mt_rand(0,9); //使用日期做文件名
	
        $name = $_FILES[$filename]["name"];
		$type = $_FILES[$filename]["type"];
		$size = $_FILES[$filename]["size"];
		$tmp_name = $_FILES[$filename]["tmp_name"];
      
        //文件类型判断
        switch ($type) {
			case 'image/pjpeg' :
			case 'image/jpeg' :
				$extend = ".jpg";
				break;
			case 'image/gif' :
				$extend = ".gif";
				break;
			case 'image/png' :
				$extend = ".png";
				break;
		}
        if (empty($extend)) {
           showmessage( "上传类型不正确！！！","?m=caswee&c=fristpage");
		}
        if ($size > $this->maxsize) {
			$maxpr = $maxsize / 1000;
            echo "警告！上传图片大小不能超过" . $maxpr . "K!";
		}
        $filename=$newname.$extend;
        if (move_uploaded_file($tmp_name, $this->upfile.$filename)) {
			return $filename;
		}
    }
}
class fristpage {
	function __construct() {
		$this->caswee_db = pc_base::load_model('caswee_fristchange');
		$this->_username = param::get_cookie('_username');
		$this->_userid = param::get_cookie('_userid');
		
  		
	}
	
	public function init() { 
	$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$infos = $this->caswee_db->listinfo($where,$order = 'id DESC',$page, $pages = '9');
  		
  	$pages = $this->caswee_db->pages;
		
	
		pc_base::load_sys_class('form', '', 0);
 		include template('caswee', 'fristpagechange');
	}  
	public function ly(){
 	
			
			
			$img= new upfiles();   //实例化类文件
            $photo = $img->upfile("file");
		
 if ($photo){

 			$id=$_POST['id'];
 		
 			$_POST['ly']['banner'] =$photo;
			$_POST['ly']['text'] =$_POST['text'];
			
			
 			
  			$this->caswee_db->update($_POST['ly'],"id=$id");
 			showmessage(L('add_success'), "?m=caswee&c=fristpage");
 		
 
 			
 }
	}
	
}
?>